<%@page import="models.config.SiteConfigModel"%>
<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
SiteConfigModel configs = (SiteConfigModel) request.getAttribute("configs");
String form = (String) request.getAttribute("form");

ImagesService imagesService = ImagesServiceFactory.getImagesService();

%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
<script type="text/javascript" src="/admin/js/form_config.js"></script>
<script type="text/javascript" src="/admin/js/configs/form_layout.js"></script>
<script type="text/javascript">
var httpCharacterSet = "<%=configs.getHttpCharacterSet()%>";
</script>
	<% if (success != null) {%>
	<div class="success block" ><%=success %></div>
	<% } %>
	<div class="block">
		<form id="edit_config_form" action="<%= blobstoreService.createUploadUrl("/admin/config/site/layout") %>" method="post" enctype="multipart/form-data">
			<div id="add_items">
				<table class="formPage">
					<thead>
						<tr>
							<th colspan="2">
								Layout Config
							</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td class="label"><label for="c_layoutSiteUrl">Site Url:</label></td>
							<td class="smallDesc type">
								<% if (check.get("layoutSiteUrl") != null) { %>
									<span class="error"><%=check.get("layoutSiteUrl") %></span>
								<% } %>
								<input id="c_layoutSiteUrl" class="text" type="text" name="layoutSiteUrl" value="<%=configs.getLayoutSiteUrl() != null ? configs.getLayoutSiteUrl() : "" %>" maxlength="100">
								<div class="description">Website Url.</div>
							</td>
						</tr>
						<tr>
							<td class="label"><label for="c_layoutCopyright">Copyright Text:</label></td>
							<td class="smallDesc type">
								<% if (check.get("layoutCopyright") != null) { %>
									<span class="error"><%=check.get("layoutCopyright") %></span>
								<% } %>
								<input id="c_layoutCopyright" class="text" type="text" name="layoutCopyright" value="<%=configs.getLayoutCopyright() != null ? configs.getLayoutCopyright() : "" %>" maxlength="100">
								<div class="description">Footer copyright Text.</div>
							</td>
						</tr>
						<tr>
							<td class="label"><label for="c_logo">Site logo:</label></td>
							<td class="smallDesc logo">
								<% if (check.get("logo") != null) { %>
									<span class="error"><%=check.get("logo") %></span>
								<% } %>
								<% 
									if (configs.getLogo() != null && !configs.getLogo().isEmpty())  {
										 BlobKey blobKey = new BlobKey(configs.getLogo());
								%>
								<img alt="" src="<%=imagesService.getServingUrl(blobKey) %>=s144"><br />
								<br />
								<a class="change-logo" id="change-logo" href="#">Change Logo</a>
								<% } %>
								<input id="c_logo" class="text" type="file" name="logo" value="<%=configs.getLogo() != null ? configs.getLogo() : "" %>" maxlength="100">
							</td>
						</tr>
					</tbody>
				</table>
				
				<table class="formPage">
					<tfoot>
						<tr>
							<td><input type="reset" class="button" title="Reset form" alt="Reset form" value="Reset" name="reset" id="reset-user-submit"></td>
							<td><input type="submit" class="button" title="Save link" alt="Save form" value="Save" name="save" id="send-user-submit"></td>
						</tr>
					</tfoot>
				</table>
			</div>
		</form>
	</div>

<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>